﻿namespace My.Hydrator.Formatters
{
    using System.ComponentModel.Composition;
    using System.ComponentModel.DataAnnotations;
    using My.Hydrator.Helpers;

    [Export(typeof(IDataTypeFormatter))]
    public class MultilineTextDataTypeFormatter : BaseDataTypeFormatter, IDataTypeFormatter
    {
        private readonly int textLength;

        public MultilineTextDataTypeFormatter()
            : this(1000)
        {
        }

        public MultilineTextDataTypeFormatter(int textLength)
        {
            this.textLength = textLength;
        }

        public virtual DataTypeAttribute FormatterDataType
        {
            get { return new DataTypeAttribute(DataType.MultilineText); }
        }

        public virtual object GetFormat()
        {
            var result = string.Empty;

            for (var i = 0; i < this.textLength; i++)
            {
                result += this.Random.NextUpperCaseLetter();
                if (this.Random.Next(0, 100) >= 85)
                {
                    result += " ";
                }
            }

            return result;
        }
    }
}
